package com.avcdata.aoscustommade.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.avcdata.aoscustommade.R;

/**
 * Created by c.c on 2017/2/26.
 * Toast工具类
 */
public class ToastUtils {
    private ToastUtils() {
        /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    public static boolean isShow = true;

    /**
     * 短时间显示Toast
     */
    public static void showShort(Context context, String message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    /**
     * 短时间显示Toast
     */
    public static void showShort(Context context, int message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    /**
     * 长时间显示Toast
     */
    public static void showLong(Context context, String message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    /**
     * 长时间显示Toast
     */
    public static void showLong(Context context, int message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    /**
     * 自定义显示Toast时间
     */
    public static void showDefine(Context context, String message, int duration) {
        if (isShow)
            Toast.makeText(context, message, duration).show();
    }

    /**
     * 自定义显示Toast时间
     */
    public static void showDefine(Context context, int message, int duration) {
        if (isShow)
            Toast.makeText(context, message, duration).show();
    }

    /**
     * 短时间的SnackBar
     * * @param
     * info 显示的信息
     */
    public static void showShortSnackBar(Activity activity, String info) {
        Snackbar snackbar = Snackbar.make(activity.getWindow().getDecorView().findViewById(android.R.id.content), info, Snackbar.LENGTH_SHORT);
        setSnackbarMessageTextColor(snackbar, Color.parseColor("#ee3939"));
        snackbar.show();
    }

    public static void setSnackbarMessageTextColor(Snackbar snackbar, int color) {
        View view = snackbar.getView();
        ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(color);
    }

    /**
     * 长时间的SnackBar
     * * @param
     * info 显示的信息
     */
    public static void showLongSnackBar(Activity activity, String info) {
        Snackbar snackbar = Snackbar.make(activity.getWindow().getDecorView().findViewById(android.R.id.content), info, Snackbar.LENGTH_LONG);
        setSnackbarMessageTextColor(snackbar, Color.parseColor("#ee3939"));
        snackbar.show();
    }


}
